﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Data;
using System.Data.OleDb;
using System.Collections.ObjectModel;
using System.Data.SQLite;
using System.ComponentModel;

namespace NUMIMAX
{
    public class Database
    {

        public static SQLiteConnection connection(string _co)
        {
            SQLiteConnection sqlConnection = new SQLiteConnection();
            sqlConnection.ConnectionString = "Data source = " + "baza.dat" + ";";
            sqlConnection.Open();
            return sqlConnection;
        }

        public static SQLiteConnection connectionClose(string _co)
        {
            SQLiteConnection sqlConnection = new SQLiteConnection();
            sqlConnection.ConnectionString = "Data source = " + "baza.dat" + ";";
            sqlConnection.Close();
            return sqlConnection;
        }

        public static SQLiteDataReader wszystko(string _co)
        {
            SQLiteDataReader sqlReader;
            SQLiteCommand sqlCommand = new SQLiteCommand(connection("baza.dat"));

            sqlCommand.CommandText = @"SELECT coins.id_coin, coins.id_cat AS Expr1, coins.id_sub, coins.name AS Expr2,
                                        coins.year_em, coins.denomin, coins.edition, coins.stamp, coins.alloy, coins.weight,
                                        coins.diameter, coins.rant, coins.nb_catalogue, coins.index1, coins.index2,
                                        coins.price_issue, coins.status, coins.id_coin_img, coins.id_coin_price,
                                        coins.id_coin_price_quarter, coins.id_coin_type, coins.rec_status AS Expr3,
                                        coins_img.id_coin_img AS Expr4, coins_img.img, coins_img.rec_status AS Expr5,
                                        coins_prices.id_coin_price AS Expr9, coins_prices.date_price_current,
                                        coins_prices.price_current, coins_prices.date_price_prev_1, coins_prices.price_prev_1,
                                        coins_prices.date_price_prev_2, coins_prices.price_prev_2,
                                        coins_prices.date_price_prev_3, coins_prices.price_prev_3, coins_prices.date_price_prev_4,
                                        coins_prices.price_prev_4, coins_prices.date_price_prev_5,
                                        coins_prices.price_prev_5, coins_prices.rec_status AS Expr10,
                                        coins_prices_quarter.id_coin_price_quarter AS Expr11,
                                        coins_prices_quarter.period_1, coins_prices_quarter.price_period_1, coins_prices_quarter.period_2,
                                        coins_prices_quarter.price_period_2, coins_prices_quarter.period_3,
                                        coins_prices_quarter.price_period_3, coins_prices_quarter.period_4,
                                        coins_prices_quarter.price_period_4, coins_prices_quarter.period_5,
                                        coins_prices_quarter.price_period_5, coins_prices_quarter.period_6,
                                        coins_prices_quarter.price_period_6, coins_prices_quarter.rec_status AS
                                        Expr12, coins_type.id_coin_type AS Expr15, coins_type.value,
                                        coins_type_conv.id_coin_type_conv, coins_type_conv.id_coin_type AS Expr16,
                                        coins_type_conv.state_1, coins_type_conv.state_2, coins_type_conv.state_3,
                                        coins_type_conv.state_4, coins_type_conv.state_5, coins_type_conv.state_6,
                                        coins_type_conv.state_7 FROM category INNER JOIN coins ON category.id_cat = coins.id_cat INNER JOIN
                                        coins_img ON coins.id_coin_img = coins_img.id_coin_img INNER JOIN
                                        coins_prices ON coins.id_coin_price = coins_prices.id_coin_price INNER JOIN
                                        coins_prices_quarter ON coins.id_coin_price_quarter = coins_prices_quarter.id_coin_price_quarter INNER JOIN
                                        coins_type ON coins.id_coin_type = coins_type.id_coin_type INNER JOIN
                                        coins_type_conv ON coins_type.id_coin_type = coins_type_conv.id_coin_type";
            sqlReader = sqlCommand.ExecuteReader();

            return sqlReader;
        }

        public static SQLiteDataReader reader(string _co)
        {
            SQLiteDataReader sqlReader;
            SQLiteCommand sqlCommand = new SQLiteCommand(connection(""));

            sqlCommand.CommandText = _co;
            sqlReader = sqlCommand.ExecuteReader();

            return sqlReader;
        }
    }
}
